package smartvillage.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import smartvillage.pojo.Order;
import smartvillage.vo.OrderVO;

import java.util.List;

@Mapper
public interface OrderMapper {
    //增加订单
    @Insert("insert into smartvillage.order_tb values(null, #{commodity}, #{buyer}, #{datetime}, 0)")
    void addOrder(Order order);

    //查询自己是买家的订单
    @Select("select o.id, c.name commodity, c.name buyer, h.name seller, o.datetime, c.img1, c.img2, o.state  " +
            "from smartvillage.order_tb o, smartvillage.commodity_tb c, smartvillage.household_tb h " +
            "where o.commodity = c.id and c.household = h.id and o.buyer = #{buyer}")
    List<OrderVO> getOrderByBuyer(Integer buyer);

    //查询自己是卖家的订单
    @Select("select o.id, c.name commodity, h.name buyer, c.name seller, o.datetime, c.img1, c.img2, o.state  " +
            "from smartvillage.order_tb o, smartvillage.commodity_tb c, smartvillage.household_tb h " +
            "where o.commodity = c.id and o.buyer = h.id and c.household = #{seller}")
    List<OrderVO> getOrderBySeller(Integer seller);

    //成交订单
    @Update("update smartvillage.order_tb set state = 1 where id = #{id}")
    void dealOrder(Integer id);
}
